// src/utils/loading.js
import { ElLoading } from 'element-plus';

let loadingInstance = null;  // 用于保存加载框的实例

// 打开加载框
export const openLoading = (message = 'Loading...', background = 'rgba(0, 0, 0, 0.7)') => {
  if (loadingInstance) {
    // 如果加载框已经打开，避免重复打开
    loadingInstance.close();
  }

  loadingInstance = ElLoading.service({
    lock: true,
    text: message,
    background,
  });
};

// 关闭加载框
export const closeLoading = () => {
  if (loadingInstance) {
    loadingInstance.close();
    loadingInstance = null;  // 清空实例，方便下一次调用
  }
};
